package vn.student.message;

import java.io.IOException;

import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;


public class ServiceHelper
{
    public static final String SOAP_ACTION_GETMSG = "http://tempuri.org/GetNewsByID";
    public static final String SOAP_ACTION_CONFIRM = "http://tempuri.org/Login";
    
    public static final String METHOD_NAME_GETMSG = "GetNewsByID";
    public static final String METHOD_NAME_REGISTER = "Register";
    public static final String NAMESPACE = "http://tempuri.org/";
    public static final String URL = "http://210.211.99.125:8084/Views/Member.asmx?";
    public static final String RESULT_GETMSG = "GetNewsByIDResult";
    private PropertyInfo setProperty(String name,Object value,Class type)
    {
	PropertyInfo pInfo=new PropertyInfo();
	pInfo.setName(name);
	pInfo.setValue(value);
	pInfo.setType(type);
	return pInfo;
    }
    
    public String getMsg(String registerId,int id)
    {
	SoapObject sObject=new SoapObject(NAMESPACE, METHOD_NAME_GETMSG);
	sObject.addProperty(setProperty("ID",id,Integer.class));
	sObject.addProperty(setProperty("RegisterID",registerId,String.class));
	
	SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapSerializationEnvelope.VER11);
	envelope.dotNet = true;
	
	envelope.setOutputSoapObject(sObject);
	HttpTransportSE androidHttpTransport = new HttpTransportSE(URL, 6000);
	try
        {
	    androidHttpTransport.call(SOAP_ACTION_GETMSG, envelope);
        }
        catch (IOException e)
        {
	    e.printStackTrace();
        }
        catch (XmlPullParserException e)
        {
	    e.printStackTrace();
        }
	
	SoapObject result=null;
	result=(SoapObject)envelope.bodyIn;
	String msg= result.getProperty(0).toString();
	return msg;
    }
}
